import { Window_Selectable } from "@/windows/Window_Selectable.js";

export class Window_BattleStatus extends Window_Selectable {
    constructor(width,height) {
        super(width,height);
    }

    init(width,height){
        this._list=[];
        this.okHandler=null;
        this.cancelHandler=null;
        this.makeItemList();
        super.init(width,height);
    }

    destroy(opts){
        super.destroy(opts);
        this._list.length=0;
        this.okHandler=null;
        this.cancelHandler=null;
    }

    row(){return this.length();}
    viewRow(){return Math.floor(this.contentsHeight()/this.itemHeight());}
    length(){return $gameParty.maxBattleMembers();}

    makeItemList(){
        this._list=$gameParty.battleMembers();
    }

    itemEnabled(index){
        return super.itemEnabled(index)&&this._list[index]?.canInput();
    }

    drawItem(index,x,y,width,height) {
        let item = this._list[index];
        if(item){
            this.drawActorName(item, x, y, 150);
            this.drawActorIcons(item, x + 150, y, 96);
            if ($dataSystem.optDisplayTp) {
                this.drawGaugeAreaWithTp(item,x+width-396,y,width);
            } else {
                this.drawGaugeAreaWithoutTp(item,x+width-396,y,width);
            }
        }
    }

    drawGaugeAreaWithTp(item,x,y,width) {
        this.drawActorHp(item, x, y, 108);
        this.drawActorMp(item, x + 123, y, 96);
        this.drawActorTp(item, x + 234, y, 96);
    }

    drawGaugeAreaWithoutTp(item,x,y,width) {
        this.drawActorHp(item, x, y, 201);
        this.drawActorMp(item, x + 216, y, 114);
    }

    setHandler(name,callback){
        if(name=='ok'){
            this.okHandler=callback;
        }else if(name=='cancel'){
            this.cancelHandler=callback;
        }
    }

    onResponse(index){
        this.okHandler?.(this._list[index],index);
    }
    onCancel(){
        this.cancelHandler?.();
    }
}